package com.norteksoft.struts.web.ec;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.extremecomponents.table.limit.Limit;
import org.extremecomponents.table.limit.Sort;

public class ECInfomationBean {
	private static Log log = LogFactory.getLog(ECInfomationBean.class);
	private int pageSize;
	private Limit limit;
	
	public ECInfomationBean(){
		
	}

	public ECInfomationBean(Limit limit, int pageSize) {
		this.limit = limit;
		this.pageSize = pageSize;
	}

	public int getCurPage() {
		return limit.getPage();
	}


	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getSortOrder() {
		return limit.getSort().getSortOrder();
	}



	public String getSortProperty() {
		return limit.getSort().getProperty();
	}


	public String getSortQuery() {
		// TODO Auto-generated method stub
		return sortQuery(limit.getSort());
	}
	
	private  String sortQuery(Sort sort) {
	       if (!sort.isSorted()) {
	    	   log.debug("!sort.isSorted()******************");
	           return "";
	       } 
	       String property = sort.getProperty();
	       String sortOrder = sort.getSortOrder();
	       return sortQuery(property, sortOrder);
	}
	private  String sortQuery(String property, String sortOrder) {
	    StringBuffer result = new StringBuffer(" ORDER BY ");
	    result.append(property);
	    result.append(" ");
	    result.append(sortOrder);
	    return result.toString();
	}
	
}
